package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.mapper.TraInfoMapper;
import com.ctgu.springboot.entity.TraInfo;
import com.ctgu.springboot.service.TraInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@Service
public class TraInfoServiceImpl extends ServiceImpl<TraInfoMapper, TraInfo> implements TraInfoService {
    @Resource
    private TraInfoMapper traInfoMapper;

    @Override
    public IPage<TraInfo> traInfoPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("tra_id");
        String name = (String) query.getParam().get("tra_name");
        String traReq = (String) query.getParam().get("tra_req");
        String traContent = (String) query.getParam().get("tra_content");


        Page<TraInfo> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<TraInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(TraInfo::getTraId, id);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(TraInfo::getTraName, name);
        }
        if (StringUtils.isNotBlank(traReq) && !"null".equals(traReq)) {
            lambdaQueryWrapper.eq(TraInfo::getTraReq, traReq);
        }
        if (StringUtils.isNotBlank(traContent) && !"null".equals(traContent)) {
            lambdaQueryWrapper.eq(TraInfo::getTraContent, traContent);
        }
        return traInfoMapper.traInfoPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<TraInfo> getList(){
        return traInfoMapper.getList();
    }
}
